package com.jia.lidao.others.ui.view;

import android.content.Context;
import android.graphics.Color;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.jia.lidao.R;
import com.jia.lidao.others.enity.Classify;


/**
 * Created by mac on 17/11/12.
 */
public class ClassifyTabView extends FrameLayout {

	private View mLeftView;

	private TextView mTextView;

	private View mRightView;
	private Classify.CategoriesBean  categoriesBean;

	public ClassifyTabView(@NonNull Context context) {
		super(context);
		initView();
	}

	public ClassifyTabView(@NonNull Context context, View mLeftView) {
		super(context);
		this.mLeftView = mLeftView;
		initView();
	}

	public ClassifyTabView(@NonNull Context context, @Nullable AttributeSet attrs, View mLeftView) {
		super(context, attrs);
		this.mLeftView = mLeftView;
		initView();
	}

	public ClassifyTabView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr, View mLeftView) {
		super(context, attrs, defStyleAttr);
		this.mLeftView = mLeftView;
		initView();
	}



	public ClassifyTabView(Context context, AttributeSet attrs) {
		super(context, attrs);
		initView();
	}

	private void initView() {
		LayoutInflater layoutInflater = LayoutInflater.from(getContext());
		View rootView = layoutInflater.inflate(R.layout.view_classify_tab, this,
				true);
		mLeftView = rootView.findViewById(R.id.view_classify_tab_left);
		mTextView = (TextView) rootView.findViewById(R.id.tv_classify_tab);
		mRightView = rootView.findViewById(R.id.view_classify_tab_right);
	}

	public void setChecked(boolean isChecked) {
		if (isChecked) {
			mTextView.setBackgroundColor(Color.WHITE);
			mLeftView.setVisibility(View.VISIBLE);
			mTextView.setTextColor(getContext().getResources()
					.getColor(R.color.common_text_green));
			mRightView.setVisibility(View.INVISIBLE);
		} else {
			mTextView.setBackgroundColor(
					getResources().getColor(R.color.common_bg_gray));
			mLeftView.setVisibility(View.INVISIBLE);
			mTextView.setTextColor(getContext().getResources()
					.getColor(R.color.common_text_3));
			mRightView.setVisibility(View.VISIBLE);
		}
	}

	public void setText(String text) {
		mTextView.setText(text);
	}

	public Classify.CategoriesBean getCategoriesBean() {
		return categoriesBean;
	}

	public void setCategoriesBean(Classify.CategoriesBean categoriesBean) {
		this.categoriesBean = categoriesBean;
	}
}
